package com.aaa.marketresearch.webclient.gwt.admin;

import com.aaa.marketresearch.webclient.gwt.domain.Family;
import com.aaa.marketresearch.webclient.gwt.domain.Goods;
import com.aaa.marketresearch.webclient.gwt.util.Requester;
import com.aaa.marketresearch.webclient.gwt.util.WebContext;
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;

/**
 * @author Nail
 */
public class AdminRequester extends Requester {

    public void getAllFamily() {
        this.doPostRequest(WebContext.getInstance().getRootContext() + "getAllFamily");
    }

    public void getFamilyMembers(Integer familyId) {
        StringBuffer postData = new StringBuffer();
        postData.append(URL.encode("data")).append("=").append(URL.encode(familyId.toString()));
        this.doPostRequest(WebContext.getInstance().getRootContext() + "getFamilyMembers", postData.toString());
    }

    public void saveFamily(Family family) {
        StringBuffer postData = new StringBuffer();
        postData.append(URL.encode("data")).append("=").append(URL.encode(family.getJSON().toString()));
        this.doPostRequest(WebContext.getInstance().getRootContext() + "saveFamily", postData.toString());
    }

    public void saveFamilyMembers(JSONArray data) {
        StringBuffer postData = new StringBuffer();
        postData.append(URL.encode("data")).append("=").append(URL.encode(data.toString()));
        this.doPostRequest(WebContext.getInstance().getRootContext() + "saveFamilyMembers", postData.toString());
    }

    public void getGoods(Integer index) {
        StringBuffer postData = new StringBuffer();
        postData.append(URL.encode("data")).append("=").append(URL.encode(index.toString()));
        this.doPostRequest(WebContext.getInstance().getRootContext() + "getGoods", postData.toString());
    }

    public void saveGoods(Goods goods) {
        StringBuffer postData = new StringBuffer();
        postData.append(URL.encode("data")).append("=").append(URL.encode(goods.getJSON().toString()));
        this.doPostRequest(WebContext.getInstance().getRootContext() + "saveGoods", postData.toString());
    }

    public void getBills(Integer index) {
        StringBuffer postData = new StringBuffer();
        postData.append(URL.encode("data")).append("=").append(URL.encode(index.toString()));
        this.doPostRequest(WebContext.getInstance().getRootContext() + "getBills", postData.toString());
    }

    public void getBillContents() {
        this.doPostRequest(WebContext.getInstance().getRootContext() + "getBillContents");
    }

}
